//
// Created by tan on 22-8-20.
//

#ifndef PCB_DATACTRL_H
#define PCB_DATACTRL_H

#include "GPoint.h"
#include "GRow.h"
#include "GLine.h"
#include "GPad.h"
#include "GSurface.h"


class DataCtrl {
private:
    // Old point to find new point
    // pointNos of lineNo

public:
    // All points
    vector<GPoint> allPoints;

    // All rows
    vector<GRow> allRows;

    // All lines
    vector<GLine> allLines;

    // All pads
    vector<GPad> allPads;

    // All surfaces
    vector<GSurface> allSurfaces;

    // pointsNo to linesNO map
    vector<set<int>> pointNoToLineNoMap;

    // linesNo to pointsNo map
    map<int, set<int>> lineNoToPointNoMap;

    // points position (x, y) to pointsNo map
    map<string, int> xyToPointNoMap;

    // lineNo to blockNo map
    map<int, int> lineNoToBlockNoMap;

    // blockNo to lineNo map
    map<int, set<int>> blockNoToLineNoMap;

    // compare two points
    static bool pointsCmp(GPoint &p1, GPoint &p2);

    // Read all lines from csv file
    DataCtrl readLines(const string &file);

    // To generate new numbers of points
    void genPointNo();

    // get lineNo by pointNo
    set<int> getLineNosByPointNo(int pointNo);

    set<int> getPointNosByLineNo(int lineNo);

    int getPointNoByXY(double x, double y);

    int getBlockNoByLineNo(int lineNo);

    set<int> getLineNosByBlockNo(int blockNo);

    void genDataObj();

    vector<GPoint> pointsBetween(double x1, double y1, double x2, double y2);

};


#endif //PCB_DATACTRL_H
